import random

china_mobile_mncs = ['00', '02', '04', '07', '08', '11', '16', '17', '39', '46', '47', '48', '49', '51', '52', '53',
                         '55', '56', '57', '58', '59', '60', '61', '62', '63', '65', '66', '67', '68', '69', '70', '71',
                         '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87',
                         '88', '89', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99']
china_unicom_mncs = ['01', '06', '09', '10', '15', '19']
china_telecom_mncs = ['03', '05', '11', '13', '14', '18']

class BaseStation:
    #国家码-运营商码-lac-ci 网络 tac 基站长编码
    network = 4
    mcc = "460"
    mnc = "00"
    lac = "0"
    ci = "0"
    tac = ""
    longCellid = ""
    spcode = "1"
    longitude = 0.0
    latitude = 0.0

    def __init__(self, mcc, mnc, lac, ci, network, tac, spcode, minLongitude, maxLongitude, minLatitude, maxLatitude):
        self.mcc = mcc
        self.mnc = mnc
        self.lac = lac
        self.ci = ci
        self.network = network
        self.tac = tac
        self.spcode = spcode
        self.longitude = random.uniform(minLongitude, maxLongitude)
        self.latitude = random.uniform(minLatitude, maxLatitude)
        if network == 4:
            self.longCellid = int(lac) * 256 + int(ci)
        elif network == 5:
            self.longCellid = int(lac) * 4096 + int(ci)
        else:
            print("network type error")

    def getBaseStation(self):
        return self.mcc + "-" + self.mnc + "-" + self.lac + "-" + self.ci


def generateBaseStation(network, tac, minLongitude, maxLongitude, minLatitude, maxLatitude):
    spcodes = [1, 2, 3]
    spcode = random.choice(spcodes)
    mnc = 1
    if spcode == 1:
        mnc = random.choice(china_mobile_mncs)
    elif spcode == 2:
        mnc = random.choice(china_unicom_mncs)
    else:
        mnc = random.choice(china_telecom_mncs)
    lacs = range(10000, 100000)
    cis = range(0, 255)
    lac = random.choice(lacs)
    ci = random.choice(cis)
    return BaseStation("460", mnc, str(lac), str(ci), network, tac, spcode,  minLongitude, maxLongitude, minLatitude, maxLatitude)


if __name__ == '__main__':
    baseStation = generateBaseStation(4, "", 116.2, 116.4, 39.9, 40.1)
    print(baseStation.getBaseStation())
    print(baseStation.network)
    print(baseStation.longCellid)
    print(baseStation.spcode)
    print(baseStation.longitude)
    print(baseStation.latitude)
